package com.wenwu.common.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class FileUtils {
	private String filePaths;// 多文件路径拼接
	private String fileNames;// 多文件名称拼接
	private String attachmentOwners;// 附件所属

	public String getFilePaths() {
		return filePaths;
	}

	public void setFilePaths(String filePaths) {
		this.filePaths = filePaths;
	}

	public String getFileNames() {
		return fileNames;
	}

	public void setFileNames(String fileNames) {
		this.fileNames = fileNames;
	}

	public String getAttachmentOwners() {
		return attachmentOwners;
	}

	public void setAttachmentOwners(String attachmentOwners) {
		this.attachmentOwners = attachmentOwners;
	}

	public List<RelicsAttachment> getFileList() {
		if (StringUtils.isNotBlank(filePaths)) {
			List<RelicsAttachment> list = null;
			RelicsAttachment relicsAttachment = null;
			Date time = new Date();
			try {
				String[] paths = filePaths.split(",");
				String[] names = fileNames.split(",");
				String[] owners = attachmentOwners.split(",");
				list = new ArrayList<RelicsAttachment>();
				for (int i = 0, a = paths.length; i < a; i++) {
					relicsAttachment = new RelicsAttachment();
					relicsAttachment.setAttachmentPath(paths[i]);
					relicsAttachment.setAttachmentName(names[i]);
					relicsAttachment.setAttachmentOwner(owners[i]);
					relicsAttachment.setUploadTime(time);
					list.add(relicsAttachment);
				}
				return list;
			} catch (Exception e) {
			} finally {
				list = null;
				relicsAttachment = null;
				time = null;
			}
		}
		return null;
	}

	public List<RelicsAttachment> getFileListByString(String filePath,
			String fileName, String attachmentOwner) {
		this.filePaths = filePath;
		this.fileNames = fileName;
		this.attachmentOwners = attachmentOwner;
		if (StringUtils.isNotBlank(filePaths)) {
			List<RelicsAttachment> list = null;
			RelicsAttachment relicsAttachment = null;
			Date time = new Date();
			try {
				String[] paths = filePaths.split(",");
				String[] names = fileNames.split(",");
				String[] owners = attachmentOwners.split(",");
				list = new ArrayList<RelicsAttachment>();
				for (int i = 0, a = paths.length; i < a; i++) {
					relicsAttachment = new RelicsAttachment();
					relicsAttachment.setAttachmentPath(paths[i]);
					relicsAttachment.setAttachmentName(names[i]);
					relicsAttachment.setAttachmentOwner(owners[i]);
					relicsAttachment.setUploadTime(time);
					list.add(relicsAttachment);
				}
				return list;
			} catch (Exception e) {
			} finally {
				list = null;
				relicsAttachment = null;
				time = null;
			}
		}
		return null;
	}

	public List<Integer> getOwnList() {
		if (StringUtils.isNotBlank(attachmentOwners)) {
			List<Integer> list = null;
			try {
				String[] owners = attachmentOwners.split(",");
				list = new ArrayList<Integer>();
				for (int i = 0, a = owners.length; i < a; i++) {
					list.add(Integer.parseInt(owners[i]));
				}
				return list;
			} catch (Exception e) {
			} finally {
				list = null;
			}
		}
		return null;
	}
}
